package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IAnswerContractService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.AnswerContractCreateValidate;
import com.mdd.admin.validate.AnswerContractUpdateValidate;
import com.mdd.admin.validate.AnswerContractSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.AnswerContractListedVo;
import com.mdd.admin.vo.AnswerContractDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/answer")
@Api(tags = "新建合同回款信息管理")
public class AnswerContractController {

    @Resource
    IAnswerContractService iAnswerContractService;

    @GetMapping("/list")
    @ApiOperation(value="新建合同回款信息列表")
    public AjaxResult<PageResult<AnswerContractListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated AnswerContractSearchValidate searchValidate) {
        PageResult<AnswerContractListedVo> list = iAnswerContractService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="新建合同回款信息详情")
    public AjaxResult<AnswerContractDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        AnswerContractDetailVo detail = iAnswerContractService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "新建合同回款信息新增")
    @PostMapping("/add")
    @ApiOperation(value="新建合同回款信息新增")
    public AjaxResult<Object> add(@Validated @RequestBody AnswerContractCreateValidate createValidate) {
        iAnswerContractService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "新建合同回款信息编辑")
    @PostMapping("/edit")
    @ApiOperation(value="新建合同回款信息编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody AnswerContractUpdateValidate updateValidate) {
        iAnswerContractService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "新建合同回款信息删除")
    @PostMapping("/del")
    @ApiOperation(value="新建合同回款信息删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iAnswerContractService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
